-
Notifications
You must be signed in to change notification settings - Fork 93
[SYCLomatic] If viewed from the translation unit, the header file <bits/stdc++.h> is included before SYCL header file, then insert the SYCL header file at the beginning of the main source file of the translation unit. #2790
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: SYCLomatic
Are you sure you want to change the base?
Conversation
…ncluded, don't insert sycl.hpp at the mainfile Signed-off-by: Jiang, Zhiwei <zhiwei.jiang@intel.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Signed-off-by: Jiang, Zhiwei <zhiwei.jiang@intel.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refines the logic for inserting the SYCL header by ensuring it is only added to the main source file when <bits/stdc++.h> is included before SYCL headers, and it also removes several redundant test cleanup commands. The key changes are:
- Removal of the commented-out file removal commands from various test files.
- Addition of a flag and mapping update when <bits/stdc++.h> is encountered in the preprocessor callbacks.
- Updating the global state and header insertion logic in AnalysisInfo to conditionally insert SYCL headers based on inclusion order.
Reviewed Changes
Copilot reviewed 31 out of 31 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
clang/test/dpct/*.cpp | Removed commented out test cleanup commands |
clang/lib/DPCT/RulesInclude/InclusionHeaders.cpp | Added check to set flag when <bits/stdc++.h> is included |
clang/lib/DPCT/PreProcessor.cpp | Updated to record files included after encountering <bits/stdc++.h> |
clang/lib/DPCT/AnalysisInfo.{h,cpp} | Adjusted header insertion logic and flag reset in the main file setter |
@@ -132,6 +132,10 @@ void IncludesCallbacks::InclusionDirective( | |||
FileInfo->setFirstIncludeOffset(LocInfo.second); | |||
LastInclusionLocationUpdater Updater(FileInfo, FilenameRange.getEnd()); | |||
|
|||
if (FileName == "bits/stdc++.h") { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Consider extracting the literal "bits/stdc++.h" into a named constant to improve maintainability and reduce the chances of typos in future modifications.
if (FileName == "bits/stdc++.h") { | |
if (FileName == BITS_STDCXX_HEADER) { |
Copilot uses AI. Check for mistakes.
@@ -1403,7 +1409,10 @@ class DpctGlobalInfo { | |||
return findObject(FileMap, FilePath); | |||
} | |||
std::shared_ptr<DpctFileInfo> getMainFile() const { return MainFile; } | |||
void setMainFile(std::shared_ptr<DpctFileInfo> Main) { MainFile = Main; } | |||
void setMainFile(std::shared_ptr<DpctFileInfo> Main) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] It would be helpful to add a brief comment in setMainFile explaining why the IsAfterBitsStdcxx flag is reset when a new main file is set, to clarify the logic for future maintainers.
Copilot uses AI. Check for mistakes.
Background: if <bits/stdc++.h> is included before the SYCL header file, it results in a compiler error.
The behavior before this PR:
If a file contains CUDA syntax, the tool inserts the SYCL header file in that file. Also, SYCL header file needs to be inserted at the beginning of the main file (to avoid
bits/stdc++.h
is included before SYCL header file). The solution has an issue:sycl.hpp
may be inserted in some pure C++ code without checking ifbits/stdc++.h
is included or not.This PR will be further refined as follows:
In the translation unit, if
bits/stdc++.h
is included before the SYCL header file, insert the SYCL header file at the beginning of the main file.